<?php
namespace app\admin\controller;
use app\admin\model\NodeModel;
use app\admin\model\ArticleModel;
use app\admin\model\FinanceModel;
use app\admin\model\StudentModel;
use think\Db;
class Index extends Base
{
    public function index()
    {
        // 获取权限菜单
        $node = new NodeModel();
        $this->assign([
            'menu' => $node->getMenu(session('rule'))
        ]);
        return $this->fetch('/index');
    }

    /**
     * 后台默认首页
     * @return mixed
     */
    public function indexPage()
    {
		// 公告
		$articleModel = new ArticleModel();
		$articles = $articleModel->getArticlesByWhere('',0,5,'add_time desc');
		// 财务提醒
		$FinModel = new FinanceModel();
		$where = [
			'finish_time' => ['>=',strtotime(date("Y-m-")."01")],
			'finish_time' => ['<',strtotime(date("Y-m-",strtotime('+1 month'))."01")],
			'status' => 0
		];
		$FinRemind = $FinModel->getInfoByWhere($where,true,0,10,'finish_time desc');
		foreach($FinRemind as $k => $v){
			$orderInfo = DB::name('order')->where('order_sn',$v['order_sn'])->field('m_id,school,major')->find();
			$FinRemind[$k]['st_name'] = DB::name('member')->where('id',$orderInfo['m_id'])->value('name');
			$FinRemind[$k]['st_major'] = $orderInfo['school']."-".$orderInfo['major'];
		}
		// 教务报名提醒
		$stModel = new StudentModel();
		$where = ['delete_status'=>0,'school_roll'=>0];
		$EnrollRemind = $stModel->getInfoByWhere($where,'','','','','','','','',true,0,10);
		// assign
		$this->assign([
            'articles' => $articles,
			'FinRemind' => $FinRemind,
			'EnrollRemind' => $EnrollRemind,
        ]);
        return $this->fetch('index');
    }
}
